using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/**
篮子
**/
public class Basket : MonoBehaviour
{
    // 篮筐
    public GameObject BasketObject;
    // 篮筐联系 1 判断是否进框
    public GameObject ContactOne { get; private set; }
    // 篮筐联系 2 检测是否进框
    public GameObject ContactTwo { get; private set; }
    // 设置 Contact 关联次数  2次说明球进
    private bool contactTimeOne = false;
    private bool contactTimeTwo = false;
    private bool contactTime = false;

    public void Awake()
    {

    }
    // Start is called before the first frame update
    void Start()
    {
        ContactOne = BasketObject.transform.Find("ContactOne").gameObject;
        ContactTwo = BasketObject.transform.Find("ContactTwo").gameObject;
        // 为组件 ContactOne 的碰撞体添加 触发事件 
        ContactOne.AddComponent<BasketTriggerHandler>();
        ContactTwo.AddComponent<BasketTriggerHandler>();
        // 给 BasketTriggerHandler 对象设置 BasketObject
        ContactOne.GetComponent<BasketTriggerHandler>().BasketObject = this;
        ContactTwo.GetComponent<BasketTriggerHandler>().BasketObject = this;
    }

    // Update is called once per frame
    void Update()
    {

    }

    /**
     * 设置 Contact 次数 是否2次，如2次 说明球进了
     */
    public void setContactTimePlus(int tag)
    {
        // tag值 是1 或者 2，做二进制运算。
        if (tag == 1)
        {
            contactTimeOne = true;
        }
        else if (tag == 2)
        {
            contactTimeTwo = true;
        }
        if (contactTimeOne && contactTimeTwo)
        {
            contactTime = true;
        }
        Debug.Log($"contactTime: {contactTime}");
        // 当进球后 记录分数
    }
}
